package xyz.xmh.pattern.structural.compositepattern;

import java.util.ArrayList;
import java.util.List;

/**
 * Employee
 * 员工实体类<br/>
 * 组合模式，将一组对象组合成一个简单地对象
 *
 * @author xuMingHai
 * @since 2021/4/30 星期五 16:34
 */
public class Employee {

    /**
     * 姓名
     */
    private final String name;

    /**
     * 部门
     */
    private final String dept;

    /**
     * 薪水
     */
    private final int salary;

    /**
     * 员工的下属
     */
    private final List<Employee> employeeList;


    public Employee(String name, String dept, int salary) {
        this.name = name;
        this.dept = dept;
        this.salary = salary;
        // 初始化属性
        employeeList = new ArrayList<>();
    }

    /**
     * 添加下属的方法
     *
     * @param employee 下属
     * @return 是否成功
     */
    public boolean addSub(Employee employee) {
        return employeeList.add(employee);
    }

    /**
     * 删除下属的方法
     *
     * @param employee 下属
     * @return 是否成功
     */
    public boolean removeSub(Employee employee) {
        return employeeList.remove(employee);
    }

    /**
     * 获取员工集合
     *
     * @return
     */
    public List<Employee> getEmployeeList() {
        return employeeList;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", dept='" + dept + '\'' +
                ", salary=" + salary +
                ", employeeList=" + employeeList +
                '}';
    }
}
